@extends('app')
@include('UEditor::head')
@section('content')
<ul class="nav nav-tabs">
    <li><a href="{{ url('/admin/teaches/organization/index')}}">信息列表</a></li>
    <li class="active"><a href="{{ url('/admin/teaches/organization/index/add') }}">信息添加</a></li>
</ul>
<form id="newsForm" method="post" action="{{url('/admin/teaches/organization/index')}}">
    <div class="panel panel-default description2">
       <div class="form-group clearfix">
            <label class="col-xs-12 col-sm-3 col-md-2 control-label">机构名称</label>
            <div class="col-sm-9 col-xs-12">
                <input type="text" class="form-control" name="name" id="name" placeholder="机构名称" value="@if(!empty($result)){{ $result->name }}@endif">
            </div>
        </div>
        <div class="form-group clearfix">
            <label class="col-xs-12 col-sm-3 col-md-2 control-label">行业分类</label>
            <div class="col-sm-3 col-xs-12" id="parent">
                <select name="type" class="form-control" id="type" onchange="getChilds('category',this.value,'parent')">
                    <option value="0">请选择分类</option>
                    @foreach($type as $tp)
                    <option value="{{ $tp->cat_id }}" @if(!empty($result)) @if(in_array($tp->cat_id,$categorys['id'])) selected @endif @endif>{{ $tp->cat_name }}</option>
                    @endforeach
                </select>
            </div>
            @if(!empty($result))
                @if($item != 5)
                @foreach($categorys['list'] as $k=>$cglist)
                    <div class="col-sm-3 col-xs-12" id="child_{{$k-$item}}">
                        <select name="child_{{ $k-$item }}" class="form-control" id="child" onchange="getChilds(this.value,'child_{{ $k-$item }}')">
                    		<option value="0">请选择分类</option>
                    		@foreach($cglist as $cgl)
                    		<option value="{{ $cgl->cat_id }}" @if(in_array($cgl->cat_id,$categorys['id'])) selected @endif>{{ $cgl->cat_name }}</option>
                    		@endforeach
                    	</select>
                    </div>
                @endforeach
                @endif
                @if($item ==5)
                <div class="col-sm-3 col-xs-12" id="child_1"></div>
                <div class="col-sm-3 col-xs-12" id="child_2"></div>
                <div class="col-sm-3 col-xs-12" id="child_3"></div>
                @elseif($item==4)
                <div class="col-sm-3 col-xs-12" id="child_2"></div>
                <div class="col-sm-3 col-xs-12" id="child_3"></div>
                @elseif($item == 3)
                <div class="col-sm-3 col-xs-12" id="child_3"></div>
                @endif
            @else
            <div class="col-sm-3 col-xs-12" id="child_1"></div>
            <div class="col-sm-3 col-xs-12" id="child_2"></div>
            <div class="col-sm-3 col-xs-12" id="child_3"></div>
            @endif
        </div> 
        <div class="form-group clearfix">
            <label class="col-xs-12 col-sm-3 col-md-2 control-label">机构封面</label>
            <div class="col-sm-9 col-xs-12">
                <input id="uploadimg" name="uploadimg" type="file" multiple="true">
                <div id="imgbox" class="dustbin">
                    <div style='width:90px; height:60px;float:left;'>
                        <img src='@if(!empty($result) && count($result->attachment)>0){{ $result->attachment->url }}@endif' /><input type='hidden' name='thumb' value='@if(!empty($result)){{ $result->thumb }}@endif' />
                    </div>
                </div>
            </div>
        </div>
         <div class="form-group clearfix">
            <label class="col-xs-12 col-sm-3 col-md-2 control-label">机构简介:</label>
            <div class="col-sm-9 col-xs-12">
                <script id="breif" name="breif"  style="width:100%;margin:0 auto;height:100px;" type="text/plain">
                </script>
            </div>
        </div>
         <div class="form-group clearfix">
            <label class="col-xs-12 col-sm-3 col-md-2 control-label">机构详情:</label>
            <div class="col-sm-9 col-xs-12">
                <script id="introduction" name="introduction"  style="width:100%;margin:0 auto;height:300px;" type="text/plain">
                </script>
           </div>
        </div>
         {{--<div class="form-group clearfix">
            <label class="col-xs-12 col-sm-3 col-md-2 control-label">优惠活动:</label>
            <div class="col-sm-9 col-xs-12">
                <script id="activities" name="activities"  style="width:100%;margin:0 auto;height:300px;" type="text/plain">
                </script>
            </div>
        </div>--}}
        <div class="form-group clearfix">
            <label class="col-sm-2 control-label">企业地址:</label>
            <div class="col-sm-2">
                <select class="form-control" onchange="childAreas(this.value,'areas','city')" name="province" id="province">
                    <option>---选择省份---</option>
                    @foreach($area as $are)
                    <option value="{{$are->area_id}}" @if(!empty($result)) @if($result->province == $are->area_id) selected @endif @endif>{{$are->title}}</option>
                    @endforeach
                </select>
            </div>
            <div class="col-sm-2">
                <select class="form-control" onchange="childAreas(this.value,'areas','area')" name="city" id="city">
                    <option>---选择市---</option>
                    @if(!empty($subarea))
                    @foreach($subarea as $subare)
                    <option value="{{$subare->area_id}}" @if(!empty($result)) @if($result->city == $subare->area_id) selected @endif @endif>{{$subare->title}}</option>
                    @endforeach
                    @endif
                </select>
            </div>
            <div class="col-sm-2">
                <select class="form-control" name="area" id="area">
                    <option>---选择地区---</option>
                    @if(!empty($thrarea))
                    @foreach($thrarea as $thrare)
                    <option value="{{$thrare->area_id}}" @if(!empty($result)) @if($result->area == $thrare->area_id) selected @endif @endif>{{$thrare->title}}</option>
                    @endforeach
                    @endif
                </select>
            </div>
            <div class="col-sm-3">
                <input type="text" class="form-control" name="address" id="address" placeholder="详细地址" value="@if(!empty($result)){{ $result->address }}@endif"">
            </div>
        </div>
        <div class="form-group clearfix">
            <label class="col-xs-12 col-sm-3 col-md-2 control-label">机构电话:</label>
            <div class="col-sm-9 col-xs-12">
                <input type="text" class="form-control" name="telphone" value="@if(!empty($result)){{ $result->telphone }}@endif" id="telphone" >
            </div>
        </div>
        <div class="form-group clearfix">
            <label class="col-xs-12 col-sm-3 col-md-2 control-label">营业时间:</label>
            <div class="col-sm-9 col-xs-12">
                <input type="text" class="form-control" name="show_at" id="show_at" value="@if(!empty($result)){{$result->show_at}}@endif" placeholder="09:00-18:00" >
            </div>
        </div>
        <input type="hidden" name="user_id" value="{{ Auth::user()->id }}">
        {!! csrf_field() !!}
        <input type="hidden" name="id" value="@if(!empty($result)){{ $result->id }}@endif">
        <div class="form-inline mt20">
            <div class="form-group">
              <input type="hidden" name="status" value="1">
              <button type="button" class="btn btn-info" onclick="saveData('/admin/teaches/organization/index','newsForm')">
                    <i class="icon-ok bigger-110"></i>
                    Submit
              </button>  
            </div>
                    
            <div class="form-group col-xs-offset-1">
                <button type="reset" class="btn">
                    <i class="icon-undo bigger-110"></i>
                    Reset
                </button>
            </div>
        </div>
    </div>
</form>

<script type="text/javascript">
<!--
    //    简介
    var ue = UE.getEditor('breif');
    ue.ready(function() {
    	var breif = '@if(!empty($result)) {!! str_replace("\n","",$result->breif) !!} @endif';
        ue.execCommand('serverparam', '_token', '{{ csrf_token() }}');//此处为支持laravel5 csrf ,根据实际情况修改,目的就是设置 _token 值.
        ue.setContent(breif); //赋值
    });
    //    介绍
    var ue1 = UE.getEditor('introduction');
    ue1.ready(function() {
    	var introduction = '@if(!empty($result)) {!! str_replace("\n","",$result->introduction) !!} @endif';
        ue1.execCommand('serverparam', '_token', '{{ csrf_token() }}');//此处为支持laravel5 csrf ,根据实际情况修改,目的就是设置 _token 值.
        ue1.setContent(introduction); //赋值

    });
    //    优惠活动
//     var ue2 = UE.getEditor('activities');
//     ue2.ready(function() {
//         ue2.execCommand('serverparam', '_token', '{{ csrf_token() }}');//此处为支持laravel5 csrf ,根据实际情况修改,目的就是设置 _token 值.
//         ue2.setContent(); //赋值

//     });

    $(function(){
        /***图片上传****/
        $("#uploadimg").uploadify({
            'formData'     : {
                'app':'organization',
                'fileField':'upfile',
                '_token':'{{ csrf_token() }}'
            },
            "width"           : 120,
            "height"          : 30,
            "queueSizeLimit"  :1,
            "swf"             : "{{ asset('/js/uploadify/uploadify.swf') }}",
            "fileObjName"     : "upfile",
            "buttonText"      : "上传图片",
            "uploader"        : '/admin/upload/uploadimg',
            'removeTimeout'	  : 1,
            'fileTypeExts'	  : '*.jpg; *.png; *.gif;',
            'onUploadSuccess':function(file, data, response){
                var data = eval('(' + data + ')');
                if (data.status == 'success') {

                    var html="<div style='width:90px; height:60px;float:left;'>"
                        +"<img src='"+data.attach+"' /><input type='hidden' name='thumb' value='"+data.attach_id+"' />"
                        +"</div>"
                    $('#imgbox').html(html);
//     	            bindImg();
                }else{
                    alert(data.msg);
                    return false;
                }

            }

        });
    });
    //-->
</script>
@endsection
